using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using 道路运输从业人员无纸化考试系统.Properties;

namespace 道路运输从业人员无纸化考试系统
{
	public class LoginForm : Form
	{
		private IContainer components = null;

		private Label label1;

		private Label label2;

		private Label label3;

		private TextBox txt_Code;

		private TextBox txt_Name;

		private ComboBox cbx_model;

		private Button btn_Login;

		private Button btn_Canel;

		public LoginForm()
		{
			InitializeComponent();
		}

		private void LoginForm_Load(object sender, EventArgs e)
		{
			txt_Code.Select();
			GetMokuai();
		}

		private void GetMokuai()
		{
			string[] attributs = new string[1]
			{
				"mokuai"
			};
			DataTable dt3 = null;
			//dt3 = GlobamParms.ReadXmlToDataTable(Application.StartupPath + "\\data\\DataXMLFile.xml", "mokuai", attributs);
            dt3= GlobamParms.ReadXmlToDataTable(GlobamParms.GetAssemblyStream(), "mokuai", attributs);
            DataTable dt = new DataTable();
			DataColumn dc3 = new DataColumn();
			dc3.ColumnName = "text";
			dt.Columns.Add(dc3);
			DataColumn dc2 = new DataColumn();
			dc2.ColumnName = "value";
			dt.Columns.Add(dc2);
			DataRow dr2 = dt.NewRow();
			dt.Rows.Add(dr2);
			dt.Rows[0][0] = "";
			dt.Rows[0][1] = "";
			DataRow dr = dt.NewRow();
			dt.Rows.Add(dr);
			dt.Rows[1][0] = dt3.Rows[0][0].ToString();
			dt.Rows[1][1] = dt3.Rows[0][0].ToString();
			cbx_model.DataSource = dt;
			cbx_model.DisplayMember = "text";
			cbx_model.ValueMember = "value";
		}

		private void btn_Login_Click(object sender, EventArgs e)
		{
			if (txt_Code.Text.Trim() == "")
			{
				MessageBox.Show("请输入证件号", "提示");
				txt_Code.Select();
			}
			else if (txt_Code.Text.Trim().Length != 15 && txt_Code.Text.Trim().Length != 18)
			{
				MessageBox.Show("请输入15位或18位的证件(身份证)号", "提示");
				txt_Code.Select();
			}
			else if (txt_Name.Text.Trim() == "")
			{
				MessageBox.Show("请输入姓名", "提示");
				txt_Name.Select();
			}
			else if (cbx_model.Text == "")
			{
				MessageBox.Show("请选择考试模块", "提示");
				cbx_model.Select();
			}
			else if (checkAdmin())
			{
				GlobamParms.name = txt_Name.Text;
				GlobamParms.code = txt_Code.Text;
				GlobamParms.type = cbx_model.Text;
				Close();
				MainForm mf = new MainForm();
				mf.TopMost = true;
				GlobamParms.mainform = mf;
				mf.Show();
			}
		}

		private bool checkAdmin()
		{
			if (txt_Name.Text == "admin")
			{
				if (txt_Code.Text == "123")
				{
					GlobamParms.name = txt_Name.Text;
					return true;
				}
				return false;
			}
			return true;
		}

		private void btn_Canel_Click(object sender, EventArgs e)
		{
			Close();
		}

		private void LoginForm_FormClosed(object sender, FormClosedEventArgs e)
		{
			if (GlobamParms.mainform != null || GlobamParms.loginform != null)
			{
				GlobamParms.firstform.WindowState = FormWindowState.Normal;
			}
			GlobamParms.loginform = null;
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing && components != null)
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}

		private void InitializeComponent()
		{
			label1 = new System.Windows.Forms.Label();
			label2 = new System.Windows.Forms.Label();
			label3 = new System.Windows.Forms.Label();
			txt_Code = new System.Windows.Forms.TextBox();
			txt_Name = new System.Windows.Forms.TextBox();
			cbx_model = new System.Windows.Forms.ComboBox();
			btn_Login = new System.Windows.Forms.Button();
			btn_Canel = new System.Windows.Forms.Button();
			SuspendLayout();
			label1.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
			label1.AutoSize = true;
			label1.BackColor = System.Drawing.Color.Transparent;
			label1.Location = new System.Drawing.Point(134, 516);
			label1.Name = "label1";
			label1.Size = new System.Drawing.Size(53, 12);
			label1.TabIndex = 0;
			label1.Text = "证件号：";
			label2.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
			label2.AutoSize = true;
			label2.BackColor = System.Drawing.Color.Transparent;
			label2.Location = new System.Drawing.Point(330, 516);
			label2.Name = "label2";
			label2.Size = new System.Drawing.Size(41, 12);
			label2.TabIndex = 0;
			label2.Text = "姓名：";
			label3.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
			label3.AutoSize = true;
			label3.BackColor = System.Drawing.Color.Transparent;
			label3.Location = new System.Drawing.Point(478, 516);
			label3.Name = "label3";
			label3.Size = new System.Drawing.Size(65, 12);
			label3.TabIndex = 0;
			label3.Text = "考试模块：";
			txt_Code.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
			txt_Code.Location = new System.Drawing.Point(181, 513);
			txt_Code.MaxLength = 18;
			txt_Code.Name = "txt_Code";
			txt_Code.Size = new System.Drawing.Size(134, 21);
			txt_Code.TabIndex = 0;
			txt_Name.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
			txt_Name.Location = new System.Drawing.Point(374, 513);
			txt_Name.Name = "txt_Name";
			txt_Name.Size = new System.Drawing.Size(82, 21);
			txt_Name.TabIndex = 1;
			txt_Name.Text = "考生名";
			cbx_model.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
			cbx_model.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			cbx_model.FormattingEnabled = true;
			cbx_model.Items.AddRange(new object[2]
			{
				"道路旅客运输驾驶员",
				"道路货物运输驾驶员"
			});
			cbx_model.Location = new System.Drawing.Point(538, 512);
			cbx_model.Name = "cbx_model";
			cbx_model.Size = new System.Drawing.Size(118, 20);
			cbx_model.TabIndex = 2;
			btn_Login.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
			btn_Login.Image = 道路运输从业人员无纸化考试系统.Properties.Resources.登陆;
			btn_Login.Location = new System.Drawing.Point(682, 507);
			btn_Login.Name = "btn_Login";
			btn_Login.Size = new System.Drawing.Size(84, 31);
			btn_Login.TabIndex = 3;
			btn_Login.UseVisualStyleBackColor = true;
			btn_Login.Click += new System.EventHandler(btn_Login_Click);
			btn_Canel.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
			btn_Canel.Image = 道路运输从业人员无纸化考试系统.Properties.Resources.取消;
			btn_Canel.Location = new System.Drawing.Point(788, 507);
			btn_Canel.Name = "btn_Canel";
			btn_Canel.Size = new System.Drawing.Size(84, 31);
			btn_Canel.TabIndex = 4;
			btn_Canel.UseVisualStyleBackColor = true;
			btn_Canel.Click += new System.EventHandler(btn_Canel_Click);
			base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 12f);
			base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			BackColor = System.Drawing.Color.White;
			BackgroundImage = 道路运输从业人员无纸化考试系统.Properties.Resources.登录主页;
			BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
			base.ClientSize = new System.Drawing.Size(1018, 721);
			base.Controls.Add(btn_Canel);
			base.Controls.Add(btn_Login);
			base.Controls.Add(cbx_model);
			base.Controls.Add(txt_Name);
			base.Controls.Add(txt_Code);
			base.Controls.Add(label3);
			base.Controls.Add(label2);
			base.Controls.Add(label1);
			base.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			base.MaximizeBox = false;
			base.MinimizeBox = false;
			base.Name = "LoginForm";
			base.ShowInTaskbar = false;
			base.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			Text = "道路运输从业人员无纸化考试系统 - Microsoft Internet Explorer";
			base.FormClosed += new System.Windows.Forms.FormClosedEventHandler(LoginForm_FormClosed);
			base.Load += new System.EventHandler(LoginForm_Load);
			ResumeLayout(false);
			PerformLayout();
		}
	}
}
